package com.tsxy.mall.mapper;

import com.tsxy.mall.entity.College;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface CollegeMapper {

    @Select({"select * from sys_college where pid is null"})
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "name",property = "name"),
            @Result(column = "pid",property = "pid"),
            @Result(column = "detail",property = "detail"),
            @Result(column = "tag",property = "tag"),
            @Result(column = "id",property = "children",
                many = @Many(select = "getByPid"))
    })
    List<College> getAll();

    @Select({"select * from sys_college where pid = #{id}"})
    List<College> getByPid(Integer id);

    @Select({"select * from sys_college where pid is null"})
    List<College> getParent();

    @Select({"select * from sys_college where pid = #{id}"})
    List<College> getByParent(Integer id);

    @Select({"select * from sys_college where id = #{collegeId}"})
    College getByCollegeId(Integer collegeId);

    @Select({"select * from sys_college where id = #{majorId}"})
    College getByMajorId(Integer majorId);
}
